# HIP_PATH?= $(wildcard /opt/rocm)
# HIPCC=$(HIP_PATH)/bin/hipcc
HIPCC="hipcc"

CXXFLAGS += -std=c++11 -O3
CLANG="/opt/rocm-6.2.4/lib/llvm/bin/clang-18"
CLANG_EXT="/mnt/llvm-16.0.6/bin/bin/clang"

CLANG_OFFLOAD_BUNDLER="/opt/rocm-6.2.4/lib/llvm/bin/clang-offload-bundler"
LLVM_LINK="/opt/rocm-6.2.4/lib/llvm/bin/lld"
HOST_LINK="/usr/bin/ld"

CLANG_RES_DIR="/opt/rocm-6.2.4/lib/llvm/lib/clang/18"

INCLUDE_OPTIONS = \
	"-internal-isystem" "${CLANG_RES_DIR}/include/cuda_wrappers" \
	"-include" "__clang_hip_runtime_wrapper.h" \
	"-internal-isystem" "/usr/include/c++/13" \
	"-internal-isystem" "/usr/include/x86_64-linux-gnu/c++/13" \
	"-internal-isystem" "/usr/include/c++/13/backward" \
	"-internal-isystem" "/opt/rocm-6.2.4/lib/llvm/lib/clang/18/include" \
	"-internal-isystem" "/usr/local/include" \
	"-internal-isystem" "/usr/include" \
	"-internal-isystem" "/usr/x86_64-linux-gnu/include" \
	"-internal-externc-isystem" "/include" \
	"-internal-externc-isystem" "/usr/include" \
	"-internal-externc-isystem" "/usr/include/x86_64-linux-gnu"

INCLUDE_OPTIONS_DEBUG = \
	"-internal-isystem" "${CLANG_RES_DIR}/include/cuda_wrappers" \
	"-include" "__clang_hip_runtime_wrapper.h" \
	"-internal-isystem" "/usr/include/c++/13" \
	"-internal-isystem" "/usr/include/x86_64-linux-gnu/c++/13" \
	"-internal-isystem" "/usr/include/c++/13/backward" \
	"-internal-isystem" "/work/llvm-16.0.6/bin/lib/clang/16/include" \
	"-internal-isystem" "/usr/local/include" \
	"-internal-isystem" "/usr/include" \
	"-internal-isystem" "/usr/x86_64-linux-gnu/include" \
	"-internal-externc-isystem" "/include" \
	"-internal-externc-isystem" "/usr/include" \
	"-internal-externc-isystem" "/usr/include/x86_64-linux-gnu"

ROCM_BITCODE = \
	"-mlink-builtin-bitcode" "${CLANG_RES_DIR}/lib/amdgcn/bitcode/hip.bc" \
	"-mlink-builtin-bitcode" "${CLANG_RES_DIR}/lib/amdgcn/bitcode/ocml.bc" \
	"-mlink-builtin-bitcode" "${CLANG_RES_DIR}/lib/amdgcn/bitcode/ockl.bc" \
	"-mlink-builtin-bitcode" "${CLANG_RES_DIR}/lib/amdgcn/bitcode/oclc_daz_opt_off.bc" \
	"-mlink-builtin-bitcode" "${CLANG_RES_DIR}/lib/amdgcn/bitcode/oclc_unsafe_math_off.bc" \
	"-mlink-builtin-bitcode" "${CLANG_RES_DIR}/lib/amdgcn/bitcode/oclc_finite_only_off.bc" \
	"-mlink-builtin-bitcode" "${CLANG_RES_DIR}/lib/amdgcn/bitcode/oclc_correctly_rounded_sqrt_on.bc" \
	"-mlink-builtin-bitcode" "${CLANG_RES_DIR}/lib/amdgcn/bitcode/oclc_wavefrontsize64_on.bc" \
	"-mlink-builtin-bitcode" "${CLANG_RES_DIR}/lib/amdgcn/bitcode/oclc_isa_version_906.bc" \
	"-mlink-builtin-bitcode" "${CLANG_RES_DIR}/lib/amdgcn/bitcode/oclc_abi_version_500.bc"

MISC_DIR = \
	"-fdebug-compilation-dir=/work/work/amd/HIP-Examples/reduction" \
	"-fmath-errno" "-resource-dir" "${CLANG_RES_DIR}" \
	"-idirafter" "/opt/rocm-6.2.4/include" \
	"-fcoverage-compilation-dir=/work/work/amd/HIP-Examples/reduction"

all: reduction

reduction: reduction.cpp
	${HIPCC} ${CXXFLAGS} -o $@ $^

ir_host: reduction.cpp
	${CLANG_EXT} -o reduction_host.ll -O3 --driver-mode=g++ -O3 -S -emit-llvm --offload-host-only -x hip reduction.cpp

assembly: reduction.cpp
	${CLANG_EXT} -o reduction.s -O3 --driver-mode=g++ -O3 -S --offload-host-only -x hip reduction.cpp

.PHONY: clean

clean:
	rm -f reduction *.o  *.tmp Makefile_*
	rm -f reduction.hipfb reduction_gfx906.out
	rm -f reduction.ll reduction.s reduction_a.s

gdb:
	gdb -ex 'set substitute-path /home/zzy/llvm-16.0.6 /work/llvm-16.0.6/' \
	--args \
	/work/llvm-16.0.6/bin/bin/clang -o reduction.ll -O3 --driver-mode=g++ -O3 -S \
	-emit-llvm --offload-host-only -x hip reduction.cpp

DUMP_DIR = "-dumpdir" "reduction-"

LLVM_IR_OPTIONS = \
	-emit-llvm

OBJ_OPTIONS = \
	"-emit-obj"

COMMON_CC_OPTIONS = \
	"-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" \
	"-discard-value-names" "-main-file-name" "reduction.cpp" \
	"-mframe-pointer=none" "-fno-rounding-math" "-mconstructor-aliases" \
	"-fmath-errno" \
	"-debugger-tuning=gdb" \
	"-O3" "-std=c++11" "-fdeprecated-macro" \
	"-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" \
	"-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fcxx-exceptions" "-fexceptions" "-fcolor-diagnostics" \
	"-vectorize-loops" "-vectorize-slp"

COMMON_CC_HIP_OPTIONS = \
	"-fcuda-allow-variadic-functions" "-cuid=8e8cc2afee7f6142" \
	"-fhip-new-launch-api" \
	"-x" "hip"

test: build_gfx906_obj build_gfx906_out build_hipfb build_obj build_final
build_gfx906_obj:
	${CLANG} "-cc1" \
	${INCLUDE_OPTIONS} \
	${ROCM_BITCODE} \
	${MISC_DIR} \
	"-triple" "amdgcn-amd-amdhsa" "-aux-triple" "x86_64-unknown-linux-gnu" \
	"-mrelocation-model" "pic" "-pic-level" "2" "-fhalf-no-semantic-interposition" \
	"-target-cpu" "gfx906" "-aux-target-cpu" "x86-64" \
	${OBJ_OPTIONS} \
	${COMMON_CC_OPTIONS} \
	${COMMON_CC_HIP_OPTIONS} \
	"-fcuda-is-device" "-mllvm" "-amdgpu-internalize-symbols" \
	"-fvisibility=hidden" "-fapply-global-visibility-to-externs" "-fno-autolink" \
	"-o" "reduction_gfx906.o" "reduction.cpp"
	@echo ""

build_gfx906_out:
	${LLVM_LINK} "-flavor" "gnu" "-m" "elf64_amdgpu" "--no-undefined" "-shared" \
	"-plugin-opt=-amdgpu-internalize-symbols" "-plugin-opt=mcpu=gfx906" "-plugin-opt=O3" "--lto-CGO3" \
	"--whole-archive" "reduction_gfx906.o" "--no-whole-archive" \
	"-o" "reduction_gfx906.out"
	@echo ""

build_hipfb:
	${CLANG_OFFLOAD_BUNDLER} "-type=o" "-bundle-align=4096" \
	"-targets=host-x86_64-unknown-linux,hipv4-amdgcn-amd-amdhsa--gfx906" "-input=/dev/null" \
	"-input=reduction_gfx906.out" "-output=reduction.hipfb"
	@echo ""

build_obj:
	${CLANG} "-cc1" \
	${INCLUDE_OPTIONS} \
	${MISC_DIR} \
	"-triple" "x86_64-unknown-linux-gnu" "-aux-triple" "amdgcn-amd-amdhsa" \
	"-mrelocation-model" "static" \
	"-target-cpu" "x86-64" "-tune-cpu" "generic" \
	${OBJ_OPTIONS} \
	${COMMON_CC_OPTIONS} \
	${COMMON_CC_HIP_OPTIONS} \
	"-funwind-tables=2" \
	"-fcuda-include-gpubinary" "reduction.hipfb" \
	"-o" "reduction.o" "reduction.cpp"
	@echo ""

build_final:
	${HOST_LINK} \
	"-z" "relro" "--hash-style=gnu" "--eh-frame-hdr" "-m" "elf_x86_64" \
	"-dynamic-linker" "/lib64/ld-linux-x86-64.so.2" \
	"-L/usr/lib/gcc/x86_64-linux-gnu/13" "-L/usr/lib64" "-L/lib/x86_64-linux-gnu" \
	"-L/lib64" "-L/usr/lib/x86_64-linux-gnu" "-L/usr/lib64" "-L/lib" "-L/usr/lib" \
	"-L/opt/rocm-6.2.4/lib" "-rpath" "/opt/rocm-6.2.4/lib" \
	"/lib/x86_64-linux-gnu/crt1.o" \
	"/lib/x86_64-linux-gnu/crti.o" "${CLANG_RES_DIR}/lib/linux/clang_rt.crtbegin-x86_64.o" \
	"reduction.o" \
	"--enable-new-dtags" \
	"-lamdhip64" "-lstdc++" "-lm" "${CLANG_RES_DIR}/lib/linux/libclang_rt.builtins-x86_64.a" \
	"-lgcc_s" "-lc" "${CLANG_RES_DIR}/lib/linux/libclang_rt.builtins-x86_64.a" "-lgcc_s" \
	"${CLANG_RES_DIR}/lib/linux/clang_rt.crtend-x86_64.o" "/lib/x86_64-linux-gnu/crtn.o" \
	"-o" "reduction" 
	@echo ""

hipfb:
	hexdump -C -n 1024 ./reduction.hipfb
	@echo ""

ir_long:
	${CLANG_EXT} "-cc1" \
	${INCLUDE_OPTIONS_DEBUG} \
	${MISC_DIR} \
	${LLVM_IR_OPTIONS} \
	-triple x86_64-unknown-linux-gnu -aux-triple amdgcn-amd-amdhsa \
	-mrelocation-model static \
	-target-cpu x86-64 -tune-cpu generic \
	-funwind-tables=2 \
	${COMMON_CC_OPTIONS} \
	${COMMON_CC_HIP_OPTIONS} \
	-o reduction.ll reduction.cpp
	@echo ""

ir_long_backup:
	${CLANG_EXT} -cc1 \
	-triple x86_64-unknown-linux-gnu -aux-triple amdgcn-amd-amdhsa \
	-emit-llvm -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name \
	vectoradd_hip.cpp -mrelocation-model static -mframe-pointer=none -fmath-errno -fno-rounding-math \
	-mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb \
	-fdebug-compilation-dir=/work/work/amd -fcoverage-compilation-dir=/work/work/amd \
	-resource-dir /opt/rocm-6.2.4/lib/llvm/lib/clang/18 \
	-internal-isystem /opt/rocm-6.2.4/lib/llvm/lib/clang/18/include/cuda_wrappers \
	-idirafter /opt/rocm-6.2.4/include \
	${INCLUDE_OPTIONS_DEBUG} \
	-O3 -fdeprecated-macro -ferror-limit 19 -fhip-new-launch-api -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions \
	-fcolor-diagnostics -vectorize-loops -vectorize-slp -fcuda-allow-variadic-functions -faddrsig \
	-D__GCC_HAVE_DWARF2_CFI_ASM=1 -o reduction.ll -x hip reduction.cpp

ir_device:
	"/mnt/llvm-16.0.6/bin/bin/clang-16" "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" "x86_64-unknown-linux-gnu" "-emit-llvm" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "reduction.cpp" "-mrelocation-model" "pic" "-pic-level" "1" "-fhalf-no-semantic-interposition" "-mframe-pointer=none" "-fno-rounding-math" "-mconstructor-aliases" "-aux-target-cpu" "x86-64" "-fcuda-is-device" "-mllvm" "-amdgpu-internalize-symbols" "-fcuda-allow-variadic-functions" "-fvisibility=hidden" "-fapply-global-visibility-to-externs" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/hip.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/ocml.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_daz_opt_off.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_unsafe_math_off.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_finite_only_off.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_correctly_rounded_sqrt_on.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_wavefrontsize64_on.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_isa_version_906.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_abi_version_400.bc" "-target-cpu" "gfx906" "-mllvm" "-treat-scalable-fixed-error-as-warning" "-debugger-tuning=gdb" "-resource-dir" "/mnt/llvm-16.0.6/bin/lib/clang/16" "-internal-isystem" "/mnt/llvm-16.0.6/bin/lib/clang/16/include/cuda_wrappers" "-idirafter" "/opt/rocm/include" "-include" "__clang_hip_runtime_wrapper.h" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/backward" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/backward" "-internal-isystem" "/mnt/llvm-16.0.6/bin/lib/clang/16/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-internal-isystem" "/mnt/llvm-16.0.6/bin/lib/clang/16/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-O3" "-fdeprecated-macro" "-fno-autolink" "-fdebug-compilation-dir=/mnt/work/gpu_book/amd/hip_example_test/reduction" "-ferror-limit" "19" "-fhip-new-launch-api" "-fgnuc-version=4.2.1" "-fcxx-exceptions" "-fexceptions" "-fcolor-diagnostics" "-vectorize-loops" "-vectorize-slp" "-cuid=c3f3e40ef035e2b7" "-fcuda-allow-variadic-functions" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "reduction_device.ll" "-x" "hip" "reduction.cpp"

asm_device:
	"/mnt/llvm-16.0.6/bin/bin/clang-16" "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" "x86_64-unknown-linux-gnu" "-S" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "reduction.cpp" "-mrelocation-model" "pic" "-pic-level" "1" "-fhalf-no-semantic-interposition" "-mframe-pointer=none" "-fno-rounding-math" "-mconstructor-aliases" "-aux-target-cpu" "x86-64" "-fcuda-is-device" "-mllvm" "-amdgpu-internalize-symbols" "-fcuda-allow-variadic-functions" "-fvisibility=hidden" "-fapply-global-visibility-to-externs" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/hip.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/ocml.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_daz_opt_off.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_unsafe_math_off.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_finite_only_off.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_correctly_rounded_sqrt_on.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_wavefrontsize64_on.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_isa_version_906.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_abi_version_400.bc" "-target-cpu" "gfx906" "-mllvm" "-treat-scalable-fixed-error-as-warning" "-debugger-tuning=gdb" "-resource-dir" "/mnt/llvm-16.0.6/bin/lib/clang/16" "-internal-isystem" "/mnt/llvm-16.0.6/bin/lib/clang/16/include/cuda_wrappers" "-idirafter" "/opt/rocm/include" "-include" "__clang_hip_runtime_wrapper.h" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/backward" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/backward" "-internal-isystem" "/mnt/llvm-16.0.6/bin/lib/clang/16/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-internal-isystem" "/mnt/llvm-16.0.6/bin/lib/clang/16/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-O3" "-fdeprecated-macro" "-fno-autolink" "-fdebug-compilation-dir=/mnt/work/gpu_book/amd/hip_example_test/reduction" "-ferror-limit" "19" "-fhip-new-launch-api" "-fgnuc-version=4.2.1" "-fcxx-exceptions" "-fexceptions" "-fcolor-diagnostics" "-vectorize-loops" "-vectorize-slp" "-cuid=b1b4a974a1c2e774" "-fcuda-allow-variadic-functions" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "reduction_device.s" "-x" "hip" "reduction.cpp"

gdb_asm_device:
	gdb --args "/mnt/llvm-16.0.6/bin/bin/clang-16" "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" "x86_64-unknown-linux-gnu" "-S" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "reduction.cpp" "-mrelocation-model" "pic" "-pic-level" "1" "-fhalf-no-semantic-interposition" "-mframe-pointer=none" "-fno-rounding-math" "-mconstructor-aliases" "-aux-target-cpu" "x86-64" "-fcuda-is-device" "-mllvm" "-amdgpu-internalize-symbols" "-fcuda-allow-variadic-functions" "-fvisibility=hidden" "-fapply-global-visibility-to-externs" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/hip.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/ocml.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_daz_opt_off.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_unsafe_math_off.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_finite_only_off.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_correctly_rounded_sqrt_on.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_wavefrontsize64_on.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_isa_version_906.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_abi_version_400.bc" "-target-cpu" "gfx906" "-mllvm" "-treat-scalable-fixed-error-as-warning" "-debugger-tuning=gdb" "-resource-dir" "/mnt/llvm-16.0.6/bin/lib/clang/16" "-internal-isystem" "/mnt/llvm-16.0.6/bin/lib/clang/16/include/cuda_wrappers" "-idirafter" "/opt/rocm/include" "-include" "__clang_hip_runtime_wrapper.h" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/backward" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/backward" "-internal-isystem" "/mnt/llvm-16.0.6/bin/lib/clang/16/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-internal-isystem" "/mnt/llvm-16.0.6/bin/lib/clang/16/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-O3" "-fdeprecated-macro" "-fno-autolink" "-fdebug-compilation-dir=/mnt/work/gpu_book/amd/hip_example_test/reduction" "-ferror-limit" "19" "-fhip-new-launch-api" "-fgnuc-version=4.2.1" "-fcxx-exceptions" "-fexceptions" "-fcolor-diagnostics" "-vectorize-loops" "-vectorize-slp" "-cuid=b1b4a974a1c2e774" "-fcuda-allow-variadic-functions" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "reduction_device.s" "-x" "hip" "reduction.cpp"

gdb_ir_device:
	gdb --args "/mnt/llvm-16.0.6/bin/bin/clang-16" "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" "x86_64-unknown-linux-gnu" "-emit-llvm" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "reduction.cpp" "-mrelocation-model" "pic" "-pic-level" "1" "-fhalf-no-semantic-interposition" "-mframe-pointer=none" "-fno-rounding-math" "-mconstructor-aliases" "-aux-target-cpu" "x86-64" "-fcuda-is-device" "-mllvm" "-amdgpu-internalize-symbols" "-fcuda-allow-variadic-functions" "-fvisibility=hidden" "-fapply-global-visibility-to-externs" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/hip.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/ocml.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_daz_opt_off.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_unsafe_math_off.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_finite_only_off.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_correctly_rounded_sqrt_on.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_wavefrontsize64_on.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_isa_version_906.bc" "-mlink-builtin-bitcode" "/opt/rocm/amdgcn/bitcode/oclc_abi_version_400.bc" "-target-cpu" "gfx906" "-mllvm" "-treat-scalable-fixed-error-as-warning" "-debugger-tuning=gdb" "-resource-dir" "/mnt/llvm-16.0.6/bin/lib/clang/16" "-internal-isystem" "/mnt/llvm-16.0.6/bin/lib/clang/16/include/cuda_wrappers" "-idirafter" "/opt/rocm/include" "-include" "__clang_hip_runtime_wrapper.h" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/backward" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/backward" "-internal-isystem" "/mnt/llvm-16.0.6/bin/lib/clang/16/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-internal-isystem" "/mnt/llvm-16.0.6/bin/lib/clang/16/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-O3" "-fdeprecated-macro" "-fno-autolink" "-fdebug-compilation-dir=/mnt/work/gpu_book/amd/hip_example_test/reduction" "-ferror-limit" "19" "-fhip-new-launch-api" "-fgnuc-version=4.2.1" "-fcxx-exceptions" "-fexceptions" "-fcolor-diagnostics" "-vectorize-loops" "-vectorize-slp" "-cuid=c3f3e40ef035e2b7" "-fcuda-allow-variadic-functions" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "reduction_device.ll" "-x" "hip" "reduction.cpp"
